/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.game.math.view.action;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.game.math.view.domain.Examination;

/**
 *
 * @author nmduc
 */
public class CheckGameAction extends AbstractAction {

    private static ResourceBundle bundle = ResourceBundle.getBundle("org.game.math.view.action.CheckGameAction");
    private static final Map<Integer, Map<Integer, Icon>> IMAGES = new HashMap<Integer, Map<Integer, Icon>>();

    static {
        for (int i = 1; i < 6; i++) {
            Map<Integer, Icon> icons = new HashMap<Integer, Icon>();
            for (int j = 1; j < 4; j++) {
                String imageIconKey = "point." + i + ".image" + j;
                icons.put(Integer.valueOf(j), new ImageIcon(CheckGameAction.class.getResource(bundle.getString(imageIconKey))));
            }
            IMAGES.put(Integer.valueOf(i), icons);
        }
    }

    @Override
    public void actionPerformed(ActionEvent ae) {
        Examination examination = Examination.getInstance();
        long points = examination.calculatePointsAndStopEditing();
        int index = Long.valueOf(points).intValue();
        int randomIndex = Long.valueOf(System.currentTimeMillis() % 3 + 1).intValue();
        JOptionPane.showMessageDialog((Component) ae.getSource(), bundle.getString("you.have") +" "+ points + " " + bundle.getString("points"), bundle.getString("pointsTitle"), JOptionPane.INFORMATION_MESSAGE, IMAGES.get(((index==0?1:index)/2)).get(randomIndex));
    }
}
